/*
 * Created on Aug 24, 2010 by Eng. Julian Rousselot
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package ar.com.visualAORE.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author julian
 *
 */

public class Document {
	private List<Requirement> requirements;
	private List<Selection> selections;
	private String name;
	private String path;
	private int documentSize;
	private int totalLineNumbers;
	
	public Document(String name, String path, int documentSize, int totalLineNumbers){
		selections = new ArrayList<Selection>();
		requirements = new ArrayList<Requirement>();
		this.name = name;
		this.path = path;
		this.documentSize = documentSize;
		this.totalLineNumbers = totalLineNumbers;
	}
	/**
	 * Devuelve todos los concerns del documento
	 * @return concerns
	 */
	public Set<Concern> getAllConcerns(){
		Selection selection = null;
		Iterator<Selection> it = selections.iterator();
		Set<Concern> concerns = new HashSet<Concern>();
		while(it.hasNext()){
			selection = it.next();
			concerns.add(selection.getConcern());
		}
		return concerns;
	}
	public void addDocumentSelection(Selection selection){
		this.selections.add(selection);
	}
	public void addDocumentRequirement(Requirement requirement){
		this.requirements.add(requirement);
	}
	
	/**
	 * Elimina una seleccion del documento
	 * @param selection
	 */
	public void removeDocumentSelection(Selection selection){
		this.selections.remove(selection);
	}
	public void removeDocumentRequirement(Requirement requirement){
		this.requirements.remove(requirement);
	}
	public List<Selection> getSelections() {
		return selections;
	}
	public List<Requirement> getRequirements() {
		return requirements;
	}
	public void setSelections(List<Selection> selections) {
		this.selections = selections;
	}
	public void setRequirements(List<Requirement> requirements) {
		this.requirements = requirements;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public int getDocumentSize() {
		return documentSize;
	}
	public void setDocumentSize(int documentSize) {
		this.documentSize = documentSize;
	}
	
	public int getTotalLineNumbers() {
		return totalLineNumbers;
	}
	public void setTotalLineNumbers(int totalLineNumbers) {
		this.totalLineNumbers = totalLineNumbers;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Document [name=" + name + ", path=" + path + ", selections="
				+ selections + "]";
	}
	
}
